package com.ruoyi.worker.service.impl;

import com.google.common.collect.Maps;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.worker.domain.AgeRange;
import com.ruoyi.worker.domain.EmploymentPlan;
import com.ruoyi.worker.domain.EmploymentPlanStatistics;
import com.ruoyi.worker.domain.OperationNeedPojo;
import com.ruoyi.worker.mapper.EmploymentPlanMapper;
import com.ruoyi.worker.service.EmploymentPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: employmentPlanServiceImpl
 * @Description: 计划用工名单业务层
 * @Author: 刘松山
 * @Date: 2021/9/12 10:28
 */
@Service
public class EmploymentPlanServiceImpl implements EmploymentPlanService {

    @Autowired
    private EmploymentPlanMapper employmentPlanMapper;
    @Autowired
    private RedisCache redisCache;

    @Override
    public int addAgeRange(AgeRange ageRange) {
        int result = employmentPlanMapper.addAgeRange(ageRange);
        setRedisCache(ageRange);
        return result;
    }

    @Override
    public int modifyAgeRange(AgeRange ageRange) {
        int result = employmentPlanMapper.modifyAgeRange(ageRange);
        setRedisCache(ageRange);
        return result;
    }

    /**
     * @Description : 设置年龄缓存
     * @Author : leizhang
     * @Date 10:48 下午 2021/9/13
     * @param ageRange
     * @return void
     **/
    private void setRedisCache(AgeRange ageRange) {
        String key = "ageRange";
        Map<String, Object> valueMap = Maps.newHashMap();
        valueMap.put("startAge", ageRange.getStartAge());
        valueMap.put("endAge", ageRange.getEndAge());
        redisCache.setCacheMap(key, valueMap);
    }

    @Override
    public AgeRange getAgeRange() {
        return employmentPlanMapper.getAgeRange();
    }

    @Override
    public int importEmploymentPlan(List<EmploymentPlan> list) {
        return employmentPlanMapper.addEmploymentPlan(list);
    }

    @Override
    public int delEmployment(Long[] ids) {
        return employmentPlanMapper.delEmployment(ids);
    }

    @Override
    public List<EmploymentPlan> listEmploymentPlan(EmploymentPlan employmentPlan) {
        return employmentPlanMapper.listEmploymentPlan(employmentPlan);
    }

    @Override
    public List<EmploymentPlanStatistics> listEmploymentPlanStatistics(EmploymentPlanStatistics employmentPlanStatistics) {
        return employmentPlanMapper.listEmploymentPlanStatistics(employmentPlanStatistics);
    }

    @Override
    public EmploymentPlan countAttendanceCompany(EmploymentPlan e) {
        return employmentPlanMapper.countAttendanceCompany(e);
    }

    @Override
    public int delAllAttendanceCompany(EmploymentPlan e) {
        return employmentPlanMapper.delAllAttendanceCompany(e);
    }

    @Override
    public int delAllEmploymentPlanStatistics(EmploymentPlan e) {
        return employmentPlanMapper.delAllEmploymentPlanStatistics(e);
    }

    @Override
    public List<EmploymentPlan> ListAttendanceCompany(EmploymentPlan e) {
        return employmentPlanMapper.ListAttendanceCompany(e);
    }

    @Override
    public int addAttendanceStatistics(EmploymentPlanStatistics employmentPlanStatistics) {
        return employmentPlanMapper.addAttendanceStatistics(employmentPlanStatistics);
    }

    @Override
    public OperationNeedPojo getworkNeedInfo(OperationNeedPojo operationNeedPojo) {
        return employmentPlanMapper.getworkNeedInfo(operationNeedPojo);
    }
}
